<!--
 * @Author: your name
 * @Date: 2021-12-27 09:15:01
 * @LastEditTime: 2022-05-10 09:26:33
 * @LastEditors: Please set LastEditors
 * @Description: 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
 * @FilePath: \cloudServiceStatic\src\components\CommonForm\SelectOption.vue
-->
<template>
<div>
  <a-select
    v-if="type === 'select'"
    :value="getValue(value)"
    @change="e=>input(e,row)"
    v-bind="$attrs"
    v-on="$listeners"
    allowClear
    placeholder="请选择"
    
  >
    <a-select-option
      v-for="(item, index) in Object.entries(enums)"
      :key="index"
      :value="getValue(item[0])"
      
      
    >
    {{item[1]}}
    </a-select-option>
  </a-select>
   <a-select
    v-else-if="type === 'multiple'"
     :value="getMultipleValue(value)"
    @change="e=>input(e,row)"
    v-bind="$attrs"
    v-on="$listeners"
    allowClear
   
    placeholder="请选择"
    
  >
    <a-select-option
      v-for="(item, index) in Object.entries(enums)"
      :key="index"
      :value="getValue(item[0])"
      
      
    >
    {{item[1]}}
    </a-select-option>
  </a-select>
  <a-radio-group name="radioGroup" v-else-if="type==='radio'" :value="value" v-bind="$attrs" @input="selectRaido"  @change="selectChange" v-on="$listeners">
    <a-radio   v-for="(item, index) in Object.entries(enums)"
      :key="index"
      :value="getValue(item[0])">
      {{item[1]}}
    </a-radio>
  </a-radio-group>
  <a-checkbox-group v-else :value="value" v-bind="$attrs" @change="selectChange" v-on="$listeners">
        <a-checkbox  :name="item[1]" v-for="(item, index) in Object.entries(enums)" :key="index"
      :value="getValue(item[0])">
      {{item[1]}}
        </a-checkbox>
  </a-checkbox-group>
  </div>
</template>

<script>
export default {
  props: {
    value: [Object, Number, String, Boolean, Array],
    enums: {
      type: Object,
      require:true
    },
    type: {
      type: String,
      default: 'select',
    },
    valueIsNumber: {
      type: Boolean,
      default: true,
    },
    row:{
      type:Object
    }
  },
  data() {
    return {
      
    }
  },
  methods: {
    getValue(val) {
      if (Number.isNaN(Number(val))) {
        return val
      }
      return this.valueIsNumber ? Number(val) : val
    },
    getMultipleValue(val){
     return val?val:[]
    },
     input(e,row) {
      this.$emit('input', e);
      this.$emit('selectOptionChange',e,row)
    },
    selectChange(e){
       this.$emit('selectChange',e)
    },
    selectRaido(e){
       this.$emit('input',e)
    },
  },
}
</script>

<style></style>
